package com.wjs.controller;

import com.github.pagehelper.PageInfo;
import com.sun.deploy.net.HttpRequest;
import com.sun.deploy.net.HttpResponse;
import com.wjs.entity.Category;
import com.wjs.entity.Tea;
import com.wjs.service.CategoryService;
import com.wjs.service.impl.CategoryServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("category")
public class CategoryController {
    private CategoryService service=new CategoryServiceImpl();
    @RequestMapping("selectAll")
    public String selectAll(HttpSession session){
        List<Category> list=service.selectAll();
        session.setAttribute("categoryList",list);
        return "redirect:/addTea.jsp";
    }
    /*@RequestMapping("selectAll2")
    public String selectAll2(HttpSession session){
        List<Category> list=service.selectAll();
        session.setAttribute("categoryList",list);
        return "/categorylist.jsp";
    }*/
    @RequestMapping("/selectAll3")
    public String selectAll3(Model model,Integer curPage){
        //设置默认页数，第一次的时候不会传过来数据所以是null就默认为第一页

        if(curPage==null){
            curPage=1;
        }

        //根据自己需要设置，一页几条数据
        int pageSize=2;

        PageInfo<Category> pi=service.selectAllByPage(curPage,pageSize);
        model.addAttribute("pi",pi);
        return "/categorylist.jsp";
    }

    @RequestMapping("/deleteByID")
    public String deleteByID(int id){
        service.deleteByID(id);

        return "/category/selectAll3.do";
    }
    @RequestMapping("/addCategory")
    public String addCategory(Category category){
        service.addCategory(category);


        return "/category/selectAll3.do";
    }
}
